package cn.cloud9.opencloud.common.util;

import cn.cloud9.opencloud.common.api.ResultMessage;
import cn.cloud9.opencloud.common.exception.ServiceException;

import java.util.Collection;
import java.util.Map;

/**
 * @author OnCloud9
 * @description
 * @project Open-Cloud
 * @date 2022年04月16日 11:48
 */
public class Assert {

    private Assert(){}

    public static void isTrue(boolean expression, ResultMessage resultMessage, Object ... params) {
        if (expression) throw new ServiceException(resultMessage, params);
    }

    public static void isFalse(boolean expression, ResultMessage resultMessage, Object ... params) {
        if (!expression) throw new ServiceException(resultMessage, params);
    }

    public static void isEmpty(Object source, ResultMessage resultMessage, Object ... params) {
        if (null == source) throw new ServiceException(resultMessage, params);
    }

    public static void isEmptyString(String source, ResultMessage resultMessage, Object ... params) {
        if (EmptyUtil.isEmptyString( source)) throw new ServiceException(resultMessage, params);
    }

    public static void isEmptyArray(Object[] sources, ResultMessage resultMessage, Object ... params) {
        if (EmptyUtil.isEmptyArray( sources)) throw new ServiceException(resultMessage, params);
    }

    public static void isEmptyCollection(Collection<?> source, ResultMessage resultMessage, Object ... params) {
        if (EmptyUtil.isEmptyCollection( source)) throw new ServiceException(resultMessage, params);
    }

    public static void isEmptyMap(Map<?, ?> source, ResultMessage resultMessage, Object ... params) {
        if (EmptyUtil.isEmptyMap( source)) throw new ServiceException(resultMessage, params);
    }




}
